document.getElementById("save").onclick=function(){
	var data={}
	data.name=$("#siteName").val()
	data.address=$("#siteAddress").val()
	data.level=$("#siteLevel").val()
	data.bank=$("#bank").val()
	data.id=getQ().siteadmin_id
	if(/^ *$/.test(data.name)){
		showErrorInfo("站点名不能为空！")
		return false;
	}
	if(/^ *$/.test(data.address)){
		showErrorInfo("站点地址不能为空！")
		return false;
	}
	if (getQ().type==="POST"){
		_data=JSON.stringify(data)
		var file=$("#img").prop("files")[0]
		var data=new FormData()
		data.append("file",file)
		data.append("data",_data)
		$.ajax({
			"url":"/site_admin/",
			"error":errorAjax,
			"beforeSend":start_load_pic,
			"complete":stop_load_pic,
			"processData":false,
			 "cache": false,
			"contentType": false,
			"data":data,
			"type":getQ().type,
			"success":function(data){
				if(responseCheck(data)){
					alert("操作成功!")
					window.opener.location.reload()
					window.close()
				}
			}
		})
	}
	else{
		data=JSON.stringify(data)
		$.ajax({
			"url":"/site_admin/",
			"error":errorAjax,
			"beforeSend":start_load_pic,
			"complete":stop_load_pic,
			"data":{"data":data},
			"type":"PUT",
			"success":function(data){
				if(responseCheck(data)){
					alert("操作成功!")
					window.opener.location.reload()
					window.close()
				}
			}
		})
	}
}
document.getElementById("siteName").focus()
function parseData(){
	$.ajax({
		"url":"/mem_level/",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"dataType":"jsonp",
		"type":"GET",
		"success":function(data){
			if(responseCheck(data)){
				var select=document.getElementById("siteLevel")
				for(var i=0;i<data.content.site_level.length;i++){
					var option=document.createElement("option")
					option.textContent=(data.content.site_level[i].site_level_id)+"级加油站"
					option.setAttribute("value",data.content.site_level[i].site_level_id)
					select.appendChild(option)
				}
				var select=document.getElementById("bank")
				for(var i=0;i<data.bank.length;i++){
					var option=document.createElement("option")
					option.textContent=(data.bank[i])
					option.setAttribute("value",data.bank[i])
					select.appendChild(option)
				}
				if (getQ().type==="PUT"){
					$("#siteName").val(getQ().name).attr("readonly",true).attr("disabled",true)
					$("#siteAddress").val(getQ().address)
					$("#bank").val(getQ().bank)
					if(getQ().img!=="" ){
						$("#showImg").attr("src",getQ().img)
					}
					$("#siteLevel").val(getQ().level)
				}
			}
		}
	})
}
document.getElementById("img").onchange=function(){
		var file=$("#img").prop("files")[0]
		var data=new FormData()
		data.append("file",file)
		data.append("id",getQ().siteadmin_id)
		$.ajax({
			"url":"/site_admin_img/",
			"error":errorAjax,
			"processData":false,
			 "cache": false,
			"contentType": false,
			"data":data,
			"type":"POST",
			"success":function(data){
				data=JSON.parse(data)
				$("#showImg").attr("src",data.content)
			}
		})
	
}
parseData()
